﻿<Window x:Class="Poet.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock" 
        xmlns:Highlighting="clr-namespace:ICSharpCode.AvalonEdit.Highlighting;assembly=ICSharpCode.AvalonEdit" 
        xmlns:local="clr-namespace:Poet" 
        Width="966" 
        Height="600"
        Title="{Binding Title, Mode=TwoWay}"
        Topmost="{Binding Topmost, Mode=TwoWay}"
        WindowState="{Binding CurrentWindowState, Mode=TwoWay}"
        WindowStartupLocation="CenterScreen" 
        TextInput="WindowTextInput" 
        KeyDown="WindowKeyDown" AllowDrop="True" DragOver="WindowDragOver" Loaded="WindowLoaded" ResizeMode="CanResizeWithGrip" Icon="/Avalon;component/Images/rose-32x32.png">
    
    <Window.Resources>
       <local:VisualStateViewModel x:Key="VisualStateViewModel"/>
      
        <ContextMenu x:Key="TrayMenu" DataContext="{StaticResource ResourceKey=VisualStateViewModel}">
            <MenuItem Header="Hide" />
            <MenuItem Header="Topmost" IsCheckable="True" IsChecked="{Binding Topmost}"/>
            <MenuItem Header="Tool Style" IsCheckable="true" Tag="ToolStyle"/>
            <Separator />
            <MenuItem Header="Exit"  />
        </ContextMenu>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    </Window.Resources>
  <Window.DataContext>
    <StaticResource ResourceKey="VisualStateViewModel"/>
  </Window.DataContext>
    
    <Window.CommandBindings>
        <CommandBinding Command="New" Executed="New"/>
        <CommandBinding Command="Open" Executed="Open"/>
        <CommandBinding Command="local:MainWindow.SaveAll" Executed="SaveAllExecuted" CanExecute="SaveAllCanExecute"/>
        <CommandBinding Command="local:MainWindow.Exit" Executed="ExitExecuted"/>
        <CommandBinding Command="Replace" Executed="ReplaceExecuted"/>
        <CommandBinding Command="Search" Executed="SearchExecuted"/>
        <CommandBinding Command="Find" Executed="FindExecuted"/>
    </Window.CommandBindings>
    
    <Window.InputBindings>
        <KeyBinding Key="S" Modifiers="Ctrl+Shift" Command="local:MainWindow.SaveAll"/>
        <KeyBinding Key="F4" Modifiers="Alt" Command="local:MainWindow.Exit"/>
    </Window.InputBindings>

    <Grid Name="Grid">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Menu Grid.Row="0" Height="21" Name="menu" Foreground="Black">
            
            <Menu.Resources>
                <Style TargetType="{x:Type Image}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuItem}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
                            <Setter Property="Opacity" Value="0.30" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Menu.Resources>
            
            <MenuItem Header="_File">

                <MenuItem Header="_New" Command="New">
                    <MenuItem.Icon>
                        <Image Source="Images/NewDocument_16x16.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Header="_Open" Command="Open">
                    <MenuItem.Icon>
                        <Image Source="Images/Open_16x16.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Header="_Save" Command="Save" Name="_saveMenuItem" >
                    <MenuItem.Icon>
                        <Image Source="Images/Save_16x16.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Header="Save _As" Command="SaveAs" Name="_saveAsMenuItem">
                    <MenuItem.Icon>
                        <Image Source="Images/Save_16x16.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Header="Save A_ll" Command="local:MainWindow.SaveAll" InputGestureText="Ctrl+Shift+S">
                    <MenuItem.Icon>
                        <Image Source="Images/SaveAllHS.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>

                <Separator />
                <MenuItem Name="itemPageSetup" Command="local:ChildWindow.PageSetup" Header="Page Set_up">
                    <MenuItem.Icon>
                        <Image Source="Images/PrintSetupHS.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>
                
                <MenuItem Name="itemPrintPreview" Command="PrintPreview" Visibility="Collapsed"/>
                
                <MenuItem Name="itemPrint" Command="Print">
                    <MenuItem.Icon>
                        <Image Source="Images/Print_16x16.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>
                <Separator />

                <MenuItem Header="_Close" Command="Close" Name="_closeMenuItem" InputGestureText="Alt+X">
                    <MenuItem.Icon>
                        <Image Source="Images/Close_16x16.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>
                
                <MenuItem Header="E_xit" InputGestureText="Alt+F4" Command="local:MainWindow.Exit">
                    <MenuItem.Icon>
                        <Image Source="Images/CloseRed_16x16.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>
                
            </MenuItem>
            
            <MenuItem Header="_Edit" Name="editMenu">

                <MenuItem Header="_Undo" Command="Undo" Name="item1">
                    <MenuItem.Icon>
                        <Image Source="Images/Undo.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Header="_Redo" Command="Redo" Name="item2">
                    <MenuItem.Icon>
                        <Image Source="Images/Redo.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>
                
                <Separator/>

                <MenuItem Header="Cu_t" Command="Cut" Name="item3">
                    <MenuItem.Icon>
                        <Image Source="Images/Cut.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Header="_Copy" Command="Copy" Name="item4">
                    <MenuItem.Icon>
                        <Image Source="Images/Copy.png" Height="16"></Image>
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Header="_Paste" Command="Paste" Name="item5">
                    <MenuItem.Icon>
                        <Image Source="Images/Paste.png" Height="16"></Image>
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Header="_Delete" Command="Delete" Name="item6">
                    <MenuItem.Icon>
                        <Image Source="Images/Delete.png" Height="16"></Image>
                    </MenuItem.Icon>
                </MenuItem>
                
                <Separator/>
                <MenuItem Command="Find">
                    <MenuItem.Icon>
                        <Image Source="Images/FindHS.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>
                
                <MenuItem Command="Search">
                    <MenuItem.Icon>
                        <Image Source="Images/FindNextHS.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Command="Replace">
                    <MenuItem.Icon>
                        <Image Source="Images/Replace_16x16.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>
                
                <MenuItem Header="_Go To Line" Command="local:ChildWindow.GoTo" InputGestureText="Ctrl+G">
                    <MenuItem.Icon>
                        <Image Source="Images/GoTo_16x16.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Select _All" Command="SelectAll" Name="item7"/>
                
            </MenuItem>
            
            <MenuItem Header="_Content">
                
                <MenuItem Header="_Documents" Click="OnShowDocumentContent"
                          ItemsSource="{Binding Documents}">
                    <MenuItem.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Title}"/>
                        </DataTemplate>
                    </MenuItem.ItemTemplate>
                </MenuItem>

                <MenuItem Header="_Tool Windows" Click="OnShowDockableContent"
                          ItemsSource="{Binding DockableContents, ElementName=dockingManager}">
                    <MenuItem.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Title}"/>
                        </DataTemplate>
                    </MenuItem.ItemTemplate>
                </MenuItem>
                
                <Separator/>
                
                <MenuItem Header="_Navigator" InputGestureText="Clrt+Tab" Click="MenuItemClick" Tag="ShowNavigatorWindow"/>
                
            </MenuItem>
            
            <MenuItem Header="F_ormat" Name="FormatMenuItem">

                <MenuItem Header="Show _Line Numbers" IsCheckable="True" IsChecked="{Binding Path=ShowLineNumbers}"/>
                
                <MenuItem Header="Text Area Options">
                
                    <MenuItem Header="_Tabs" IsCheckable="True" IsChecked="{Binding Path=Options.ShowTabs}"/>
                
                    <MenuItem Header="_Spaces" IsCheckable="True" IsChecked="{Binding Path=Options.ShowSpaces}"/>
                
                    <MenuItem Header="_Ends Of Line" IsCheckable="True" IsChecked="{Binding Path=Options.ShowEndOfLine}"/>
                
                    <MenuItem Header="_Control Characters" IsCheckable="True" IsChecked="{Binding Path=Options.ShowBoxForControlCharacters}"/>
                
                </MenuItem>
                    
                <MenuItem Header="_Word Wrap" IsCheckable="True" IsChecked="{Binding Path=WordWrap}"/>
               
                <Separator/>
                
                <MenuItem Header="_Font" Click="MenuItemClick" Tag="Font" Command="local:ChildWindow.Font">
                    <MenuItem.Icon>
                        <Image Source="Images/FontHS.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>
                
            </MenuItem>
            
            <MenuItem Header="_View">

                <MenuItem Header="_Topmost" IsCheckable="True" IsChecked="{Binding Topmost}"/>

                <MenuItem Header="_Compact" Click="MenuItemClick" Tag="Compact"/>

                <Separator/>
                
            

                <MenuItem Header="Light View" Click="MenuItemClick" Tag="LightView"/>
                <MenuItem Header="Standart View" Click="MenuItemClick" Tag="StandartView"/>
                <MenuItem Header="Rich View" Click="MenuItemClick" Tag="RichView"/>
                
                <Separator/>
                
                <MenuItem Header="Toolbars">
                    <MenuItem Name="StandartToolBarVisibilityMenuItem" Header="Standart" IsCheckable="True"/>
                    <MenuItem Name="TextAreaOptionsToolBarVisibilityMenuItem" Header="Text Area Options" IsCheckable="True"/>
                    <MenuItem Name="HighlightToolBarVisibilityMenuItem" Header="Highlight" IsCheckable="True"/>
                </MenuItem>

                <MenuItem Header="Status Bar" Name="MainStatusBarVisibilityMenuItem" IsCheckable="True"/>

                <Separator/>
                
                <MenuItem Header="Themes">
                    
                    <MenuItem Header="Aero" Tag="aero.normalcolor">
                     
                            <MenuItem Header="Custom" Click="MenuItemClick" Tag="ChangeAeroThemeColor"/>

                            <Separator/>

                            <MenuItem Header="Green" Click="ChangeColor"/>
                            <MenuItem Header="Orange" Click="ChangeColor"/>
                            <MenuItem Header="Gray" Click="ChangeColor"/>
                            <MenuItem Header="Yellow" Click="ChangeColor"/>
                      
                    </MenuItem>
                    
                    <MenuItem Header="Classic" Tag="classic" Click="ChangeStandardTheme"/>
                    <MenuItem Header="Luna.Normalcolor" Tag="luna.normalcolor" Click="ChangeStandardTheme"/>
                    <MenuItem Header="Generic" Tag="generic" Click="ChangeStandardTheme"/>
                    <Separator/>
                    <MenuItem Header="Dev 2010" Tag="/AvalonDock.Themes;component/themes/dev2010.xaml" Click="ChangeCustomTheme"/>
                    <MenuItem Header="Expression Dark" Tag="/AvalonDock.Themes;component/themes/ExpressionDark.xaml" Click="ChangeCustomTheme"/>
                    <Separator/>
                    <MenuItem Header="Default" Click="SetDefaultTheme"/>
                </MenuItem>

            </MenuItem>
                        
            <MenuItem Header="_Help">
                <MenuItem Header="View _Help" Click="MenuItemClick" Tag="Help"/>
                <Separator/>
                <MenuItem Header="_About" Click="MenuItemClick" Tag="About"/>
            </MenuItem>
    
        </Menu>

        <ToolBarTray Grid.Row="1" Name="ToolBarTray">

            <ToolBar Name="StandartToolBar"  
                     Visibility="{Binding ElementName=StandartToolBarVisibilityMenuItem, Path=IsChecked,  Mode=TwoWay,  
                Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}">
                
                <ToolBar.Resources>
                    <Style TargetType="{x:Type Image}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ButtonBase}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
                                <Setter Property="Opacity" Value="0.30" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ToolBar.Resources>
                
                <Button Command="New">
                    <Image Source="Images/NewDocument_16x16.png" Height="16"/>
                    <Button.ToolTip>New Document (Ctrl+N)</Button.ToolTip>
                </Button>
                
                <Button Command="Open">
                    <Image Source="Images/Open_16x16.png" Height="16"/>
                    <Button.ToolTip>Open File (Ctrl+O)</Button.ToolTip>
                </Button>
                
                <Button Command="Save" Name="button7">
                    <Image Source="Images/Save_16x16.png" Height="16"/>
                    <Button.ToolTip>Save File (Ctrl+S)</Button.ToolTip>
                </Button>
                
                <Button Command="local:MainWindow.SaveAll">
                    <Image Source="Images/SaveAllHS.png" Height="16"/>
                    <Button.ToolTip>Save All</Button.ToolTip>
                </Button>
                
                <Separator/>
                
                <Button Name="button1" Command="Cut">
                    <Image Source="Images/Cut.png" Height="16"/>
                    <Button.ToolTip>Cut (Ctrl+X)</Button.ToolTip>
                </Button>
                
                <Button Name="button2" Command="Copy">
                    <Image Source="Images/Copy.png" Height="16"/>
                    <Button.ToolTip>Copy (Ctrl+C)</Button.ToolTip>
                </Button>
                
                <Button Name="button3" Command="Paste">
                    <Image Source="Images/Paste.png" Height="16"/>
                    <Button.ToolTip>Paste (Ctrl+V)</Button.ToolTip>
                </Button>
                
                <Button Name="button4" Command="Delete">
                    <Image Source="Images/Delete.png" Height="16"/>
                    <Button.ToolTip>Delete (Del)</Button.ToolTip>
                </Button>
                
                <Separator/>
                
                <Button Name="button5" Command="Undo">
                    <Image Source="Images/Undo.png" Height="16"/>
                    <!--local:AutoGreyableImage Source="Images/Undo.png" Height="16"/-->
                    <Button.ToolTip>Undo (Ctrl+Z)</Button.ToolTip>
                </Button>
                
                <Button Name="button6" Command="Redo">
                    <Image Source="Images/Redo.png" Height="16"/>
                    <Button.ToolTip>Redo (Ctrl+Y)</Button.ToolTip>
                </Button>
                
            </ToolBar>

            <ToolBar Name="FormatToolBar"
                     Visibility="{Binding ElementName=TextAreaOptionsToolBarVisibilityMenuItem, Path=IsChecked, Mode=TwoWay,
                Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}">
                
                <CheckBox IsChecked="{Binding Path=ShowLineNumbers}">
                    <TextBlock Width="16" TextAlignment="Center">#</TextBlock>
                    <CheckBox.ToolTip>Show Line Numbers</CheckBox.ToolTip>    
                </CheckBox>
                
                <CheckBox Name ="foldingCheckBox" IsChecked="{Binding Path=Folding}">
                    <TextBlock Width="16" TextAlignment="Center">+</TextBlock>
                    <CheckBox.ToolTip>Folding</CheckBox.ToolTip>
                </CheckBox>
                
                <CheckBox Name="flowCheckBox" Click="CheckBox8Click">
                    <TextBlock Name="checkBox8text" Width="16" TextAlignment="Center">→</TextBlock>
                    <CheckBox.ToolTip>Flow Direction</CheckBox.ToolTip>
                </CheckBox>
                
                <CheckBox IsChecked="{Binding Path=WordWrap}">
                    <Image Source="Images/WordWrap.png" Height="16"/>
                    <CheckBox.ToolTip>Word Wrap</CheckBox.ToolTip>
                </CheckBox>
                
                <Separator/>
                
                <CheckBox IsChecked="{Binding Path=Options.ShowTabs}">
                    <TextBlock Width="16" TextAlignment="Center" FontWeight="Bold">»</TextBlock>
                    <CheckBox.ToolTip>Show Tabs</CheckBox.ToolTip>
                </CheckBox>
                
                <CheckBox IsChecked="{Binding Path=Options.ShowSpaces}">
                    <TextBlock Width="16" TextAlignment="Center">•</TextBlock>
                    <CheckBox.ToolTip>Show Spaces</CheckBox.ToolTip>
                </CheckBox>
                
                <CheckBox IsChecked="{Binding Path=Options.ShowEndOfLine}">
                    <TextBlock Width="16" TextAlignment="Center">¶</TextBlock>
                    <CheckBox.ToolTip>Show Ends Of Lines</CheckBox.ToolTip>
                </CheckBox>
                
                <CheckBox IsChecked="{Binding Path=Options.ShowBoxForControlCharacters}">
                    <TextBlock Width="16" TextAlignment="Center">♥</TextBlock>
                    <CheckBox.ToolTip>Show Control Characters</CheckBox.ToolTip>
                </CheckBox>
                            
            </ToolBar>

            <ToolBar Name="HighlightToolBar"  
                     Visibility="{Binding ElementName=HighlightToolBarVisibilityMenuItem, Path=IsChecked, Mode=TwoWay, 
                Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}">
                <ComboBox Width="80"
				SelectedItem="{Binding Path=SyntaxHighlighting, Mode=TwoWay}"
				ItemsSource="{Binding Source={x:Static Highlighting:HighlightingManager.Instance}, Path=HighlightingDefinitions}" 
                          SelectionChanged="ComboBox1SelectionChanged">
                    <ComboBox.ToolTip>Syntax Highlighting</ComboBox.ToolTip>
                </ComboBox>
            </ToolBar>
            
        </ToolBarTray>       

        <ad:DockingManager Grid.Row="2" Name="dockingManager" 
                           DocumentsSource="{Binding Documents}" 
                           ActiveContentChanged="DockingManagerActiveContentChanged" 
                           Drop="DockingManagerDrop" 
                           PreviewMouseDoubleClick="DockingManagerPreviewMouseDoubleClick" PreviewMouseDown="DockingManagerPreviewMouseDown" ActiveDocumentChanged="DockingManagerActiveDocumentChanged">
            <ad:ResizingPanel Name="resizingPanel">
                <ad:DocumentPane Name="documentPane"/>
            </ad:ResizingPanel>           
        </ad:DockingManager>

        <StatusBar Grid.Row="3" Name="MainStatusBar"
                   Visibility="{Binding ElementName=MainStatusBarVisibilityMenuItem, Path=IsChecked, Mode=TwoWay,
            Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}">

            <StatusBarItem Name="HelpStatusBarItem" Content="Space -> New, Enter -> Open" HorizontalContentAlignment="Right" HorizontalAlignment="Right"/>
            <StatusBarItem Name="FilePathStatusBarItem" Content="{Binding ElementName=dockingManager, Path=ActiveContent.Title, Mode=OneWay,
                Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}"  HorizontalAlignment="Right"/>
                   
            <StatusBarItem HorizontalAlignment="Right" Name="LineNumberStatusBarItem">jhkhj</StatusBarItem>
            
         </StatusBar>
      
    </Grid>
</Window>
